﻿Shader "Unlit/WaterPosBlender"
{
    Properties
    {
        _MainTex("Main Texture", 2D) = "white" {}
        _Dim("Dim", float) = 0
    }
    SubShader
    {
        Tags{"RenderType" = "Opaque" "Queue" = "Geometry"}
        Pass
        {
            Tags{"LightMode" = "ForwardBase"}
            CGPROGRAM

            #pragma vertex vert
            #pragma fragment frag 

            #include "Lighting.cginc"
            #include "AutoLight.cginc"
            
            float _Dim;
            sampler2D _MainTex;
            float _DropCount;
            float4 _DropPos[1000];
            float4 _MainTex_ST;



            struct v2f{
                float4 pos : SV_POSITION;
                float2 uv : TEXCOORD0;
                float3 worldPos : TEXCOORD1;
            };

            float metaballdis(float2 pos, float2 loc)
            {
                float2 dis = pos - loc;
                return abs(0.05/dot(dis, dis));
            }
            
            v2f vert(appdata_base v)
            {
                v2f o;
                o.pos = UnityObjectToClipPos(v.vertex);
                o.worldPos = mul(unity_ObjectToWorld, v.vertex);
                o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
                return o;
            }

            fixed4 frag(v2f i) : SV_Target
            {
                float3 worldpos= i.worldPos;    
                float dis = 0;
                for(int i = 0; i < _DropCount; ++i)
                {
                    dis += metaballdis(_DropPos[i].xz, worldpos.xz);
                }
                if(dis > 9.0)    
                    return fixed4(0.2, 0.3, 0.4, 1.0);
                return fixed4(0, 0, 0, 1.0);
            }
            ENDCG
        }
    }
    FallBack "Specular"
}
